using IM.Easy.Infrastructure.Query;
using Microsoft.AspNetCore.Mvc;
using IM.Easy.SystemServices.Dtos;
using IM.Easy.SystemServices.IServices;
using IM.Easy.Entity.System;
using IM.Easy.Core.Attributes;

namespace IM.Easy.Api.Controllers.System
{
    /// <summary>
    /// FileTypesController 控制器
    /// </summary>
    [Route("system/filetypes")]
    public class FileTypesController : ControllerBase
    {
        private readonly IFileTypesService _service;

        /// <summary>
        /// 构造函数，注入服务
        /// </summary>
        /// <param name="service">服务接口</param>
        public FileTypesController(IFileTypesService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取所有FileTypes对象
        /// </summary>
        /// <returns>返回FileTypes列表</returns>
        [HttpGet]
        [Api(Name = "获取文件类型列表", Perm = "filetypes:list")]
        public PageResponse<FileTypes> GetList([FromQuery] FileTypesQueryDto query)
        {
            return _service.GetPageList(query);
        }

        /// <summary>
        /// 根据ID获取FileTypes对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns>返回指定的FileTypes对象</returns>
        [HttpGet("{id}")]
        [Api(Name = "获取文件类型", Perm = "filetypes:info")]
        public FileTypes GetById([FromRoute] Guid id)
        {
            var result = _service.GetById(id);
            return result ?? throw new KeyNotFoundException($"未找到ID为 {id} 的FileTypes对象。");
        }

        /// <summary>
        /// 创建新的FileTypes对象
        /// </summary>
        /// <param name="entity">要创建的FileTypes对象</param>
        /// <returns>返回创建后的FileTypes对象</returns>
        [HttpPost]
        [Api(Name = "新增文件类型", Perm = "filetypes:add")]
        public FileTypes Create([FromBody] FileTypes entity)
        {
            _service.Create(entity);
            return entity; // 直接返回创建的实体
        }

        /// <summary>
        /// 更新现有的FileTypes对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <param name="entity">更新后的FileTypes对象</param>
        [HttpPut]
        [Api(Name = "更新文件类型", Perm = "filetypes:put")]
        public void Update([FromBody] FileTypes entity)
        {
            _service.Update(entity);
        }

        /// <summary>
        /// 批量删除FileTypes对象
        /// </summary>
        /// <param name="ids">对象的IDS</param>
        [HttpDelete]
        [Api(Name = "删除文件类型", Perm = "filetypes:del")]
        public void Delete([FromBody] Guid[] ids)
        {
            _service.Delete(ids);
        }

    }
}
